﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using Baosight.Platform.Core.UI.Controls;
using Baosight.Platform.Core;
using Baosight.ZNH.ZMCommon;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Telerik.Windows.Controls;
using System.Collections.ObjectModel;
using System.Windows.Browser;
using System.Text;
using System.Windows.Controls;
using Baosight.Platform.Core.ServiceModel;
using Baosight.ZNH.ZMCT.UI.PopWindows;


namespace Baosight.ZNH.ZMCT.UI
{
    public partial class ZMCT22 : EFViewCmes
    {
        public ZMCT22()
        {
            InitializeComponent();
        }

        public override void Initialize(EIInfo initData)
        {
            base.Initialize(initData);
            base.BeforeAction += OnBeforeAction;
        }

        /// <summary>
        /// 列表中修改、删除前设置属性、参数
        /// 传递到后台代码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.EFGridCheckedRows = this.ChildGrid.GetCheckedEIRows();
            base.ViewProperty = _view;
        }

        public override void OnInsertButtonClick(object sender, RoutedEventArgs e)
        {
            Button _button = sender as Button;
            _button.IsEnabled = false;
            base.TempButton = _button;

            EIInfo info = new EIInfo();
            info.Set("service", "ZMCT22");
            info.Set("method", "queryPerson");
            info.Set("fdModelId", this.fdModelId.Value);
            HttpServiceAgent agent = new HttpServiceAgent();
            agent.CallService(info, doWorkCompleted);
            
        }

        private void doWorkCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            OpenPersonPopup(e.EIInfo, "短信模板配置-新增人员", "insert", null);
        }

        /// <summary>
        /// 构造模板页面内容、弹出页面
        /// </summary>
        /// <param name="eIInfo"></param>
        /// <param name="title"></param>
        private void OpenPersonPopup(EIInfo _eIInfo, string _title, string _dialogType, string _args)
        {
            SelectPerson selectPage = new SelectPerson();//构造一个新的页面
            selectPage.EIDataContext = new Platform.Core.UI.EIDataContext();
            selectPage.EIDataContext.Update(_eIInfo);
            selectPage.fdModelId.Value = this.fdModelId.Value;

            CmesWindows _popup = new CmesWindows();//构造一个弹出页面
            _popup.WindowStartupLocation = Telerik.Windows.Controls.WindowStartupLocation.CenterOwner;
            _popup.ResizeMode = ResizeMode.NoResize;//设置不能修改窗口大小
            _popup.Header = _title == null ? "" : _title;//设置Title
            _popup.Content = selectPage;//让新增页面在弹出窗口显示
            _popup.Closed += new EventHandler<WindowClosedEventArgs>(CmesWindow_Closed);

            _popup.ShowDialog();//模态显示弹出窗口
        }

        /// <summary>
        /// 弹出窗口关闭时执行的方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CmesWindow_Closed(object sender, WindowClosedEventArgs e)
        {
            if (e.DialogResult == true)
            {
                this.ChildGrid.Refresh();//刷新Grid区域
            }

            //按钮生效
            base.TempButtonOpen(true);

            //超链接生效
            if (base.TempHyperlink != null)
            {
                base.TempHyperlink.IsEnabled = true;
                base.TempHyperlink = null;
            }
        }
    }
}
